
import allure
from selenium.webdriver.common.by import By
from cloud_po.pages.base_page import BasePage


class ChannelAddPage(BasePage):
    __INPUT_CNAME = (By.XPATH, "(//*[@class='el-input__inner'])[1]")
    __INPUT_CHEAD = (By.XPATH, "//*[text()='渠道负责人']/..//input[@class='el-select__input']")
    __CHOOSE_CHEAD = (By.XPATH,"//*[@class='el-select-dropdown el-popper is-multiple']//li[2]")
    __INPUT_CGROUP = (By.XPATH, "(//*[@class='el-input__inner'])[7]")
    __INPUT_CWECHAT = (By.XPATH, "(//*[@class='el-input__inner'])[9]")
    __SAVE_BTN = (By.XPATH, "//span[text()='提交']")

    def add_channel(self,channel_name):
        """添加微信类型的渠道"""
        with allure.step("填写渠道表单"):
            self.do_send_keys(channel_name,self.__INPUT_CNAME)

            # 尝试多次点击
            self.do_find(self.__INPUT_CHEAD).click()
            self.web_locate_presence(self.__CHOOSE_CHEAD)
            self.do_find(self.__CHOOSE_CHEAD).click()

            self.do_find(self.__INPUT_CGROUP).click()
            # 下拉选滚轮滚到执行位置
            element = self.web_locate_click((By.XPATH,"//span[text()='渠道测试6群']"))
            self.driver.execute_script("arguments[0].scrollIntoView(true);", element)
            self.click_with_js((By.XPATH,"//span[text()='渠道测试6群']"))

            self.click_with_js(self.__INPUT_CWECHAT)
            self.do_find((By.CSS_SELECTOR, ".el-select-dropdown__item.wx-receive")).click()
        with allure.step("点击提交"):
            self.do_find(self.__SAVE_BTN).click()
        from cloud_po.pages.channel_page import ChannelPage
        return  ChannelPage(self.driver)
